﻿using System;
using System.Linq;
using System.Web;
using ASPNETVN.PORTAL.Components.Configuration;
using ASPNETVN.PORTAL.Components.Configuration.Items;
using ASPNETVN.PORTAL.Components.UI;
using System.Collections;

namespace ASPNETVN.PORTAL.Administration.Module
{
    public partial class StandardSetting : AddEditItemControl
    {
        private Components.Configuration.Items.Module GetModule()
        {
            PortalDataSet ds = PortalConfiguration.GetPortalDataSet();
            PortalDataSet.ModuleRow moduleRow = ds.Module.FindByID(this.ModuleID);
            return Components.Configuration.Items.Module.LoadModuleRow(moduleRow);
        }

        protected override void OnInit(EventArgs e)
        {
            this.Update += new EventHandler(StandardSetting_Update);
            ButtonUpdate = this.btnApply;
            ButtonCancel = this.btnCancel;

            base.OnInit(e);
        }

        void StandardSetting_Update(object sender, EventArgs e)
        {
            object value = this.GetModule();
            if (value != null)
            {
                Components.Configuration.Items.Module m = (Components.Configuration.Items.Module)value;

                PortalConfiguration config = new PortalConfiguration();
                config.UpdateModule(this.ModuleID, m.SortOrder, m.PaneName, chkShowEveryWhere.Checked, moduleTitle.Text, Int32.Parse(cacheTime.Text));

                this.ReturnToReferrerPage();
               
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {
                object value = this.GetModule();
                if (value != null)
                {
                    Components.Configuration.Items.Module m = (Components.Configuration.Items.Module)value;
                    moduleTitle.Text = m.Title;
                    cacheTime.Text = m.CacheTimeOut.ToString();
                    chkShowEveryWhere.Checked = m.ShowEveryWhere;
                }
            }
        }
    }
}
